package com.google.code.mochaccino.framework.jmx.thread;
/*
 * Copyright 2012 Claude Houle claude.houle@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import javax.management.openmbean.CompositeData;

public class JmxValueThread {

	private Long                  blockedCount;
	private Long                  blockedTime;
	private JmxValueMonitorInfo[] lockedMonitors;
	private JmxValueLockInfo[]    lockedSynchronizers;
	private String                lockName;
	private Long                  lockOwnerId;
	private String                lockOwnerName;
	private String[]              stackTraceElements;
	private Long                  threadId;
	private String                threadName;
	private String                threadState;
	private Long                  waitedCount;
	private Long                  waitedTime;

	public JmxValueThread() {
	}

	public JmxValueThread( CompositeData data ) {
		lockName = (String) data.get( "lockName" );
		lockOwnerId = (Long) data.get( "lockOwnerId" );
		lockOwnerName = (String) data.get( "lockOwnerName" );
		blockedTime = (Long) data.get( "blockedTime" );
		blockedCount = (Long) data.get( "blockedCount" );
		threadId = (Long) data.get( "threadId" );
		threadName = (String) data.get( "threadName" );
		threadState = (String) data.get( "threadState" );
		waitedCount = (Long) data.get( "waitedCount" );
		waitedTime = (Long) data.get( "waitedTime" );
		CompositeData[] rawStackTraceElements = (CompositeData[]) data.get( "stackTrace" );
		if ( rawStackTraceElements != null ) {
			int i = 0;
			stackTraceElements = new String[rawStackTraceElements.length];
			for ( CompositeData d : rawStackTraceElements ) {
				stackTraceElements[i] = new JmxValueStackTraceElement( d ).toString();
				i++;
			}
		}
		CompositeData[] rawLockedSynchronizers = (CompositeData[]) data.get( "lockedSynchronizers" );
		if ( rawLockedSynchronizers != null ) {
			int i = 0;
			lockedSynchronizers = new JmxValueLockInfo[rawLockedSynchronizers.length];
			for ( CompositeData d : rawLockedSynchronizers ) {
				lockedSynchronizers[i] = new JmxValueLockInfo( d );
				i++;
			}
		}
		CompositeData[] rawLockedMonitors = (CompositeData[]) data.get( "lockedMonitors" );
		if ( rawLockedMonitors != null ) {
			int i = 0;
			lockedMonitors = new JmxValueMonitorInfo[rawLockedMonitors.length];
			for ( CompositeData d : rawLockedMonitors ) {
				lockedMonitors[i] = new JmxValueMonitorInfo( d );
				i++;
			}
		}
	}

	public Long getBlockedCount() {
		return blockedCount;
	}

	public Long getBlockedTime() {
		return blockedTime;
	}

	public String getLockName() {
		return lockName;
	}

	public Long getLockOwnerId() {
		return lockOwnerId;
	}

	public String getLockOwnerName() {
		return lockOwnerName;
	}

	public JmxValueMonitorInfo[] getLockedMonitors() {
		return lockedMonitors;
	}

	public JmxValueLockInfo[] getLockedSynchronizers() {
		return lockedSynchronizers;
	}

	public String[] getStackTraceElements() {
		return stackTraceElements;
	}

	public Long getThreadId() {
		return threadId;
	}

	public String getThreadName() {
		return threadName;
	}

	public String getThreadState() {
		return threadState;
	}

	public Long getWaitedCount() {
		return waitedCount;
	}

	public Long getWaitedTime() {
		return waitedTime;
	}
}
